package m1;


import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //创建生产者对象
        DefaultMQProducer p = new DefaultMQProducer("prod-group1");
        //设置name server
        p.setNamesrvAddr("192.168.64.131:9876");
        //启动连接
        p.start();

        //创建消息封装对象Message(Topic Tag)

        //发送
        while (true){
            System.out.println("输入消息: ");
            String str = new Scanner(System.in).nextLine();
            //Topic相当于是一级分类
            //Tag相当于是二级分类
            Message msg = new Message("Topic1","TagA",str.getBytes());
            msg.setDelayTimeLevel(3);//设置消息级别
            SendResult r = p.send(msg);
            System.out.println(r);
        }
    }
}
